package org.example.sync;

import java.util.NavigableMap;
import java.util.NavigableSet;
import java.util.concurrent.ConcurrentNavigableMap;
import java.util.concurrent.ConcurrentSkipListMap;

public class ConcurrentNavigableMapTest {


    public static void main(String[] args) {
        ConcurrentNavigableMap<String, Integer> navigableMap = new ConcurrentSkipListMap<>();

        navigableMap.put("1", 1);
        navigableMap.put("2", 2);

        navigableMap.put("3", 3);

        navigableMap.put("4", 4);

        System.out.println(navigableMap);
        //返回一个相反的顺序
        NavigableSet<String> keys = navigableMap.descendingKeySet();
        System.out.println(keys);
        //返回此映射中包含的映射的逆顺序视图
        ConcurrentNavigableMap<String, Integer> descendingMap =
                navigableMap.descendingMap();
        System.out.println(descendingMap);

        //返回从这个Map的key是严格小于 toKey部分 <
        ConcurrentNavigableMap<String, Integer> headMap1 =
                navigableMap.headMap("2");
        System.out.println(headMap1);

        // <=
        ConcurrentNavigableMap<String, Integer> headMap2 =
                navigableMap.headMap("2", true);
        System.out.println(headMap2);


        NavigableSet<String> navigableSet = navigableMap.keySet();

        System.out.println(navigableSet);


        NavigableSet<String> navigableSet1 = navigableMap.navigableKeySet();
        System.out.println(navigableSet1);


        //返回从这个Map的键范围从 fromKey到 toKey部分
        NavigableMap<String, Integer> subMap1 = navigableMap.subMap("1", false, "3", true);
        NavigableMap<String, Integer> subMap2 = navigableMap.subMap("1", "3");
        System.out.println(subMap1);
        System.out.println(subMap2);


        //返回从这个Map的关键是大于或等于 fromKey部分。
        NavigableMap<String, Integer> tailMap1 = navigableMap.tailMap("3");
        NavigableMap<String, Integer> tailMap2 = navigableMap.tailMap("3", true);
        System.out.println(tailMap1);
        System.out.println(tailMap2);
    }
}
